﻿using System.Collections.Specialized;
using System.IO;
using Rodunu.Movies.Contracts;
using Rodunu.Movies.Services.Interfaces.Netflix;
using Rodunu.Movies.Services.NetFlix.DataProvider;

namespace Rodunu.Movies.Services.NetFlix.Logic
{
    public class ManageAtHome : NetflixServiceBase, IManageAtHome
    {
        #region Constructors

        public ManageAtHome(string tokenKey)
            : base(tokenKey)
        {
            
        }

        public ManageAtHome()
        {

        }

        public ManageAtHome(UserInfo userId)
            : base(userId)
        {

        }

        #endregion

        #region IManageAtHome Members

        public Models.Netflix.AtHome GetMoviesAtHome(int startIndex)
        {
            var parameters = new NameValueCollection();
            parameters.Add("start_index", startIndex.ToString());
            parameters.Add("max_results", "25");
            return (Models.Netflix.AtHome)
                _serializationHelper.FromXml(typeof(Models.Netflix.AtHome),
                new StreamReader(_netflixService.GetUserResource("http://api.netflix.com/users/{userid}/at_home", parameters).GetResponseStream()).ReadToEnd());
        }

        #endregion
    }
}
